<?php
class Register_Year_Endpoint{
	
	
	public function __construct(){
		add_filter('query_vars', array($this, 'add_query_vars'), 0);
		add_action('init', array($this, 'add_endpoint'), 0);
	}	
	
	/** Add public query vars
	*	@param array $vars List of current public query vars
	*	@return array $vars 
	*/
	public function add_query_vars($vars){
		$vars[] = 'register_year';
		return $vars;
	}
	
	/** Add API Endpoint
	*	This is where the magic happens - brush up on your regex skillz
	*	@return void
	*/
	public function add_endpoint(){
		add_rewrite_rule('^/usuario/registro-consumo/(2[0-9]{3})/?','/usuario/registro-consumo/?register_year=$matches[1]','top');
	}
 
	
}
new Register_Year_Endpoint();